import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class Main {
    private static Logger logger = LogManager.getLogger(Main.class.getName());
    public static void main(String[] args) throws InstantiationException, IllegalAccessException {
        try {

            ReadClassNameFromXML avaliableXml = new ReadClassNameFromXML();
            String nowFilePath = "src//config.xml";

            Class classOfDiscount = Class.forName(avaliableXml.getClassName(nowFilePath));
            Object objectOfDiscount = classOfDiscount.newInstance();
            Discount testDiscount = (Discount) objectOfDiscount;

            MovieTicket testMovieTicket = new MovieTicket();

            testMovieTicket.setDiscount(testDiscount);

            testMovieTicket.setPrice(100);

            System.out.println(outPut(testMovieTicket.getPrice(),avaliableXml.getClassName(nowFilePath)));
            logger.debug(outPut(testMovieTicket.getPrice(),avaliableXml.getClassName(nowFilePath)));
            logger.error(outPut(testMovieTicket.getPrice(),avaliableXml.getClassName(nowFilePath)));
            logger.fatal(outPut(testMovieTicket.getPrice(),avaliableXml.getClassName(nowFilePath)));
            logger.info(outPut(testMovieTicket.getPrice(),avaliableXml.getClassName(nowFilePath)));
            logger.warn(outPut(testMovieTicket.getPrice(),avaliableXml.getClassName(nowFilePath)));
        }
        catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } finally {

        }
    }

    public static String outPut(double price,String name){
        String out = "";
        if(name.equals("VipDiscount")){
            out = "VIP折扣后支付"+price+"元";
        }
        else if (name.equals("StudentDiscount")){
            out = "学生折扣后支付"+price+"元";
        }
        else if (name.equals("ChildrenDiscount")){
            out = "儿童折扣后支付"+price+"元";
        }
        return out;
    }
}
